"""写一个支持加减乘除的整数计算器
"""

def calculate(a: int, b: int, operation: str):
    if operation == '+':
        return a + b
    elif operation == '-':
        return a - b
    elif operation == '*':
        return a * b
    elif operation == '/':
        if b == 0:
            raise ValueError("除数不能为0")
        return a / b
    else:
        raise ValueError(f"不支持的运算符: {operation}")

a= int(input("请输入第一个整数："))
b= int(input("请输入第二个整数："))
operation= input("请输入运算符：")
print(calculate(a, b, operation))



# def calc(first_num, second_num, operator):
#     """
#     :param first_num: 第一个数字,除法的时候,它是被除数,减法同理
#     :param second_num: 第二个数字
#     :param operator: 运算符,仅支持'+', '-', '*', '/'
#     :return: 返回对应运算的结果
#     """
#     if not isinstance(first_num, int) and isinstance(second_num, int):
#         raise TypeError('请输入整数')
#     if operator not in ('+', '-', '*', '/'):
#         raise ValueError('请输入正确的运算符')
#     try:
#         if operator == '+':
#             return first_num + second_num
#         elif operator == '-':
#             return first_num - second_num
#         elif operator == '*':
#             return first_num * second_num
#         elif operator == '/':
#             if second_num == 0:
#                 raise ValueError('除数不能为0!')
#             else:
#                 return first_num / second_num
#     except TypeError as e:
#         raise TypeError('请输入整数')
#
# print(calc(5, 10, '/'))


# '''使用递归计算第n项的阶乘值
# 使用递归拆分多层列表（有一个列表，深度不可知，列表里面还会嵌套列表，把这个列表展开生成新的列表，且元素顺序不变）'''
# def factorial_of_n(n):
#     if n == 0:
#         return  1
#     else:
#         return n*factorial_of_n(n-1)
# n = int(input("请输入一个正整数n："))
# print(f"输入的正整数{n}的阶乘为：{factorial_of_n(n)}")
#
#
# '''列表展开'''
#
#
# def list_expand(ls):
#     new_ls = []
#     for i in ls:
#         if isinstance(i, list):
#             new_ls.extend(list_expand(i))
#         else:
#             new_ls.append(i)
#     return new_ls

"""1.定义一个函数，检查一个字符串是否是回文（正读和反读都一样）
2.定义一个函数，找出列表中的最大值
3.定义一个函数，计算列表中所有正数的平均值
4.定义一个函数，将字符串中的每个单词反转，但保持单词间的顺序不变
5.定义一个函数，计算一个字符串中每个字符出现的次数，并以字典形式返回
"""

# def str1(s):
#     return s == s[::-1]
# print(str1('abcba'))


# # print(is_palindrome('aba'))
#
# # todo 2.定义一个函数，找出列表中的最大值
# def max_num_for_ls(ls):
#     max_num = ls[0]
#     for i in ls:
#         if i > max_num:
#             max_num = i
#     return max_num
#
#
# # print(max_num_for_ls([4, 32, 5, 12, 4, 214, 53, 8, 6, 3, 3, 123]))
#
# # todo 3.定义一个函数，计算列表中所有正数的平均值
# def average_postive_num(ls):
#     new_ls = [i for i in ls if i > 0]
#     sum_num = 0
#     for j in new_ls:
#         sum_num += j
#     return sum_num / len(new_ls)
#
#
# # print(average_postive_num([-1,-2,-3,-4,1,2]))
#
# # todo 4.定义一个函数，将字符串中的每个单词反转，但保持单词间的顺序不变
#
# def revers_words_in_string(s):
#     result = []
#     new_ls = []
#     for i in s:
#         if i.isalnum():
#             new_ls.append(i)
#         else:
#             if new_ls:
#                 result.append(''.join(new_ls[::-1]))
#             result.append(i)
#             new_ls = []
#     if new_ls: # 处理最后一个单词
#         result.append(''.join(new_ls[::-1]))
#     return ''.join(result)
#
# # a = 'hello,world!'
# # print(revers_words_in_string(a))
#
# # todo 5.定义一个函数，计算一个字符串中每个字符出现的次数，并以字典形式返回
# def char_count(s):
#     count_dic = {}
#     for  i in s:
#         if i in count_dic:
#             count_dic[i] +=1
#         else:
#             count_dic[i] = 1
#     return count_dic
# print(char_count('dsahddnnei1dnmka'))


# todo 画一个每个边不同颜色的矩形
# from turtle import  *
# width(4)
# forward(200)
# # 右转90度:
# right(90)
#
# # 笔刷颜色:
# pencolor('red')
# forward(100)
# right(90)
#
# pencolor('green')
# forward(200)
# right(90)
#
# pencolor('blue')
# forward(100)
# right(90)
#
# done()
# """调用done()使得窗口等待被关闭，否则将立刻关闭窗口:"""

